package EA.testproblems;
import RKUjava.math.RKUGeometry;
import RKUjava.util.RKUStringUtils;

/** This package represents an optima in a numerical optimization problem.
    Besides containing the point and the fitness it also contains a number
    of methods to relate a point in the searchspace to the optima.<br>
    The class is mainly used as a supportclass for the NumericalProblem class.
    @see EA.testproblems.NumericalProblem
 */
public class NumericalOptimum
{

  /** The point in the searchspace where this optimum is located. */
  public double[] optimum;

  /** Fitness of the problem at that optimum. */
  public double fitness;

  /** Is the optimum a maximum or a minimum. */
  public boolean ismaximum;

  /** Is the optimum known to be a global/local optimum(true) or is it the
      best found yet (false)?
  */ 
  public boolean isoptimum;

  /** Optimumindex. This can be used to store an arrayindex for e.g. 
      knownoptimums in NumericalProblem. */
  public int optimumindex;

  /** Create a new numerical optimum. */
  public NumericalOptimum(double[] theoptimum, double thefitness, boolean ismax, boolean isopt, int index)
    {
      super();
      optimum = theoptimum;
      fitness = thefitness;
      ismaximum = ismax;
      isoptimum = isopt;
      optimumindex = index;
    }

  /** Measure the distance from realpos to this optimum. */
  public double distanceToOptimum(double[] realpos)
    {
      return RKUGeometry.distancePoint2Point(optimum, realpos);
    }

  /** Get the position of the optimum. */
  public double[] getPos()
    {
      return optimum;
    }

  /** Set the position of the optimum. */
  public void setPos(double[] newpos)
    {
      for (int i=0;i<optimum.length;i++) {
	optimum[i] = newpos[i];
      }
    }

  /** Get the fitness. */
  public double getFitness()
    {
      return fitness;
    }

  /** Set the fitness. */
  public void setFitness(double newfitness)
    {
      fitness = newfitness;
    }

}
